#!/bin/bash

software_dir="BRIARMBG"
venv_name="amdgpu"
RUN_SCRIPT="run_${software_dir}.sh"

#下载文件
[ ! -d "$software_dir" ] && git clone https://github.com/camenduru/BRIA-RMBG-1.4-hf.git $software_dir
cd $software_dir
[ ! -d "$venv_name" ] && python3 -m venv $venv_name
source $venv_name/bin/activate

#安装环境
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.0
pip3 install -r requirements.txt

echo "建立启动脚本"
if [ ! -f "$RUN_SCRIPT" ]; then
    cat > $RUN_SCRIPT <<EOF
#!/bin/bash
source $venv_name/bin/activate
export HSA_OVERRIDE_GFX_VERSION=11.0.0
python app.py
EOF
    chmod +x $RUN_SCRIPT
fi

echo "安装完成"